package com.top.art.tool;

import com.top.art.vo.AccountInfoVO;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * The type Auth tool.
 *
 * @author hjh
 */
public class AuthTool {

    /**
     * The constant USER_ATTR.
     */
    public final static String USER_ATTR = "art_user";

    /**
     * Current request http servlet request.
     *
     * @return the http servlet request
     */
    public static HttpServletRequest currentRequest() {
        ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
        return attr.getRequest();
    }

    /**
     * Current user account info.
     *
     * @return the account info
     */
    public static AccountInfoVO currentUser() {
        HttpServletRequest request = currentRequest();
        return (AccountInfoVO) request.getAttribute(USER_ATTR);
    }
}
